#include "Log.h"
#include "StringUtil.h"

namespace OCPP {
    static const char* logLevelStr[Log::LogLevel::kNumberOfLogLevels] = {
    " TRACE ",
    " DEBUG ",
    " INFO  ",
    " WARN  ",
    " ERROR ",
    " FATAL ",
    };

    Log::Log(LogLevel level_)
    {
        StringStream s;
        s << StringUtil::getTime() << " " << std::this_thread::get_id();

        _logStream << s.str() << String(logLevelStr[level_], 7);
    }	
    
    Log::~Log()
    {
        auto& oFunc = outputFunc_();
        if (!oFunc)
            return;
        oFunc(_logStream.bufferData(), _logStream.bufferLength());
    }

    Log::LogLevel Log::_logLevel = kInfo;
}